<!DOCTYPE html>
<html lang=zh>
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="utf-8">
  
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-transform">
  <meta http-equiv="Cache-Control" content="no-siteapp">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="format-detection" content="telephone=no,email=no,adress=no">
  <!-- Color theme for statusbar -->
  <meta name="theme-color" content="#000000">
  <!-- 强制页面在当前窗口以独立页面显示,防止别人在框架里调用页面 -->
  <meta http-equiv="window-target" content="_top">
  
  
  <title>Git基础使用方法 | 王竹兴 | Blob</title>
  <meta name="description" content="概述 Git是一个免费的开源分布式版本控制系统，设计用于处理从小型到大型的所有项目，速度和效率都很高。  Git命令行 参考:   Git基本应用   官方Git使用文档    提交代码  1. 配置用户 12git config --global user.email &amp;quot;xxx@meitu.com&amp;quot;git config --global user.name &amp;quot;xxx">
<meta name="keywords" content="git">
<meta property="og:type" content="article">
<meta property="og:title" content="Git基础使用方法">
<meta property="og:url" content="http://zhulao.gitee.io/blog/2019/02/20/Git基础使用方法/index.html">
<meta property="og:site_name" content="王竹兴 | Blog">
<meta property="og:description" content="概述 Git是一个免费的开源分布式版本控制系统，设计用于处理从小型到大型的所有项目，速度和效率都很高。  Git命令行 参考:   Git基本应用   官方Git使用文档    提交代码  1. 配置用户 12git config --global user.email &amp;quot;xxx@meitu.com&amp;quot;git config --global user.name &amp;quot;xxx">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="http://ww1.sinaimg.cn/large/929ea2a1gy1g0rne34np7j20vk0h2jtf.jpg">
<meta property="og:image" content="http://ww1.sinaimg.cn/large/929ea2a1gy1g0rneocjm6j20ya0i40v5.jpg">
<meta property="og:image" content="http://ww1.sinaimg.cn/large/929ea2a1gy1g0rnezdcd7j20ni0jy7dk.jpg">
<meta property="og:image" content="http://ww1.sinaimg.cn/large/929ea2a1gy1g0rnftbi3uj21co0yax0c.jpg">
<meta property="og:image" content="http://ww1.sinaimg.cn/large/929ea2a1gy1g0rnge192dj20xa0icgnp.jpg">
<meta property="og:image" content="http://ww1.sinaimg.cn/large/929ea2a1gy1g0rnjartq4j21dk0vm4ac.jpg">
<meta property="og:image" content="http://ww1.sinaimg.cn/large/929ea2a1gy1g0rnjnzoyfj21mc0xw7wh.jpg">
<meta property="og:updated_time" content="2019-04-27T14:13:20.927Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Git基础使用方法">
<meta name="twitter:description" content="概述 Git是一个免费的开源分布式版本控制系统，设计用于处理从小型到大型的所有项目，速度和效率都很高。  Git命令行 参考:   Git基本应用   官方Git使用文档    提交代码  1. 配置用户 12git config --global user.email &amp;quot;xxx@meitu.com&amp;quot;git config --global user.name &amp;quot;xxx">
<meta name="twitter:image" content="http://ww1.sinaimg.cn/large/929ea2a1gy1g0rne34np7j20vk0h2jtf.jpg">
  <!-- Canonical links -->
  <link rel="canonical" href="http://zhulao.gitee.io/blog/2019/02/20/Git基础使用方法/index.html">
  
    <link rel="alternate" href="/atom.xml" title="王竹兴 | Blog" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png" type="image/x-icon">
  
  <link rel="stylesheet" href="/blog/css/style.css">
  
  
  
  
</head>


<body class="main-center" itemscope itemtype="http://schema.org/WebPage">
  <header class="header" itemscope itemtype="http://schema.org/WPHeader">
  <div class="slimContent">
    <div class="navbar-header">
      
      
      <div class="profile-block text-center">
        <a id="avatar" href="https://github.com/wzx3" target="_blank">
          <img class="img-circle img-rotate" src="/blog/images/avatar.jpeg" width="200" height="200">
        </a>
        <h2 id="name" class="hidden-xs hidden-sm">王竹兴</h2>
        <h3 id="title" class="hidden-xs hidden-sm hidden-md"></h3>
        <small id="location" class="text-muted hidden-xs hidden-sm"><i class="icon icon-map-marker"></i> XiaMen, China</small>
      </div>
      
      <div class="search" id="search-form-wrap">

    <form class="search-form sidebar-form">
        <div class="input-group">
            <input type="text" class="search-form-input form-control" placeholder="搜索">
            <span class="input-group-btn">
                <button type="submit" class="search-form-submit btn btn-flat" onclick="return false;"><i class="icon icon-search"></i></button>
            </span>
        </div>
    </form>
    <div class="ins-search">
  <div class="ins-search-mask"></div>
  <div class="ins-search-container">
    <div class="ins-input-wrapper">
      <input type="text" class="ins-search-input" placeholder="想要查找什么..." x-webkit-speech>
      <button type="button" class="close ins-close ins-selectable" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
    </div>
    <div class="ins-section-wrapper">
      <div class="ins-section-container"></div>
    </div>
  </div>
</div>


</div>
      <button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#main-navbar" aria-controls="main-navbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
    </div>
    <nav id="main-navbar" class="collapse navbar-collapse" itemscope itemtype="http://schema.org/SiteNavigationElement" role="navigation">
      <ul class="nav navbar-nav main-nav menu-highlight">
        
        
        <li class="menu-item menu-item-home">
          <a href="/blog/.">
            
            <i class="icon icon-home-fill"></i>
            
            <span class="menu-title">首页</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives">
            
            <i class="icon icon-archives-fill"></i>
            
            <span class="menu-title">归档</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories">
            
            <i class="icon icon-folder"></i>
            
            <span class="menu-title">分类</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-tags">
          <a href="/blog/tags">
            
            <i class="icon icon-tags"></i>
            
            <span class="menu-title">标签</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-repository">
          <a href="/blog/repository">
            
            <i class="icon icon-project"></i>
            
            <span class="menu-title">项目</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-about">
          <a href="/blog/about">
            
            <i class="icon icon-cup-fill"></i>
            
            <span class="menu-title">关于</span>
          </a>
        </li>
        
      </ul>
      
	
    <ul class="social-links">
    	
        <li><a href="https://github.com/wzx3" target="_blank" title="Github" data-toggle="tooltip" data-placement="top"><i class="icon icon-github"></i></a></li>
        
        <li><a href="/blog/atom.xml" target="_blank" title="Rss" data-toggle="tooltip" data-placement="top"><i class="icon icon-rss"></i></a></li>
        
    </ul>

    </nav>
  </div>
</header>

  
    <aside class="sidebar" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    
      <div class="widget">
    <h3 class="widget-title">公告</h3>
    <div class="widget-body">
        <div id="board">
            <div class="content">
                <p>人生最快意的事情之一, 就是你比别人牛逼, 然后静静的看别人在你面前装逼。</p>
            </div>
        </div>
    </div>
</div>

    
      
  <div class="widget">
    <h3 class="widget-title">分类</h3>
    <div class="widget-body">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/blog/categories/便签/">便签</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/教程/">教程</a><span class="category-list-count">22</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/游记/">游记</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/随笔/">随笔</a><span class="category-list-count">6</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">标签云</h3>
    <div class="widget-body tagcloud">
      <a href="/blog/tags/DL/" style="font-size: 13.25px;">DL</a> <a href="/blog/tags/Debug/" style="font-size: 13.5px;">Debug</a> <a href="/blog/tags/Doc/" style="font-size: 13px;">Doc</a> <a href="/blog/tags/Hexo/" style="font-size: 13.25px;">Hexo</a> <a href="/blog/tags/Links/" style="font-size: 13px;">Links</a> <a href="/blog/tags/Linux/" style="font-size: 13.25px;">Linux</a> <a href="/blog/tags/Mac/" style="font-size: 13px;">Mac</a> <a href="/blog/tags/bazel/" style="font-size: 13px;">bazel</a> <a href="/blog/tags/c-c/" style="font-size: 13.75px;">c/c++</a> <a href="/blog/tags/git/" style="font-size: 13px;">git</a> <a href="/blog/tags/rst/" style="font-size: 13px;">rst</a> <a href="/blog/tags/scripts/" style="font-size: 13.75px;">scripts</a> <a href="/blog/tags/ssh/" style="font-size: 13px;">ssh</a> <a href="/blog/tags/国学经典/" style="font-size: 13px;">国学经典</a> <a href="/blog/tags/持续集成/" style="font-size: 13.25px;">持续集成</a> <a href="/blog/tags/科幻小说/" style="font-size: 14px;">科幻小说</a>
    </div>
  </div>

    
      
  <div class="widget">
    <h3 class="widget-title">归档</h3>
    <div class="widget-body">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2019/05/">五月 2019</a><span class="archive-list-count">6</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2019/04/">四月 2019</a><span class="archive-list-count">10</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2019/03/">三月 2019</a><span class="archive-list-count">6</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2019/02/">二月 2019</a><span class="archive-list-count">10</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">最新文章</h3>
    <div class="widget-body">
      <ul class="recent-post-list list-unstyled no-thumbnail">
        
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/随笔/">随笔</a>
              </p>
              <p class="item-title">
                <a href="/blog/2019/05/26/读论语/" class="title">读论语</a>
              </p>
              <p class="item-date">
                <time datetime="2019-05-26T01:45:07.000Z" itemprop="datePublished">2019-05-26</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/随笔/">随笔</a>
              </p>
              <p class="item-title">
                <a href="/blog/2019/05/20/读变型战争/" class="title">读变型战争</a>
              </p>
              <p class="item-date">
                <time datetime="2019-05-20T15:51:57.000Z" itemprop="datePublished">2019-05-20</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/随笔/">随笔</a>
              </p>
              <p class="item-title">
                <a href="/blog/2019/05/20/读星际远征/" class="title">读黑客横行</a>
              </p>
              <p class="item-date">
                <time datetime="2019-05-20T15:40:09.000Z" itemprop="datePublished">2019-05-20</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/教程/">教程</a>
              </p>
              <p class="item-title">
                <a href="/blog/2019/05/15/代码格式化工具-clang-format/" class="title">代码格式化工具:clang-format</a>
              </p>
              <p class="item-date">
                <time datetime="2019-05-15T14:39:51.000Z" itemprop="datePublished">2019-05-15</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/教程/">教程</a>
              </p>
              <p class="item-title">
                <a href="/blog/2019/05/12/Linux-疑难杂症/" class="title">Linux 疑难杂症</a>
              </p>
              <p class="item-date">
                <time datetime="2019-05-12T02:50:29.000Z" itemprop="datePublished">2019-05-12</time>
              </p>
            </div>
          </li>
          
      </ul>
    </div>
  </div>
  

    
  </div>
</aside>

  
  
<aside class="sidebar sidebar-toc collapse" id="collapseToc" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    <nav id="toc" class="article-toc">
      <h3 class="toc-title">文章目录</h3>
      <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#git命令行"><span class="toc-number">1.</span> <span class="toc-text"> Git命令行</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#提交代码"><span class="toc-number">1.1.</span> <span class="toc-text"> 提交代码</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1-配置用户"><span class="toc-number">1.1.1.</span> <span class="toc-text"> 1. 配置用户</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-查看文件状态"><span class="toc-number">1.1.2.</span> <span class="toc-text"> 2. 查看文件状态</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3-添加到缓存"><span class="toc-number">1.1.3.</span> <span class="toc-text"> 3. 添加到缓存</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#4-提交到本地仓库"><span class="toc-number">1.1.4.</span> <span class="toc-text"> 4. 提交到本地仓库</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#5-推送到远端"><span class="toc-number">1.1.5.</span> <span class="toc-text"> 5. 推送到远端</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#拉取指定分支"><span class="toc-number">1.2.</span> <span class="toc-text"> 拉取指定分支</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#拉取子模块"><span class="toc-number">1.3.</span> <span class="toc-text"> 拉取子模块</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#切换分支"><span class="toc-number">1.4.</span> <span class="toc-text"> 切换分支</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1-查看当前分支"><span class="toc-number">1.4.1.</span> <span class="toc-text"> 1. 查看当前分支</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-创建分支"><span class="toc-number">1.4.2.</span> <span class="toc-text"> 2. 创建分支</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3-切换分支"><span class="toc-number">1.4.3.</span> <span class="toc-text"> 3. 切换分支</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#4-合并分支"><span class="toc-number">1.4.4.</span> <span class="toc-text"> 4. 合并分支</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#5-删除分支"><span class="toc-number">1.4.5.</span> <span class="toc-text"> 5. 删除分支</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#丢弃某个文件的更改"><span class="toc-number">1.5.</span> <span class="toc-text"> 丢弃某个文件的更改</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#将本地非空工程与远端创建的新仓库关联"><span class="toc-number">1.6.</span> <span class="toc-text"> 将本地非空工程与远端创建的新仓库关联</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#查看提交记录"><span class="toc-number">1.7.</span> <span class="toc-text"> 查看提交记录</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#骚操作"><span class="toc-number">2.</span> <span class="toc-text"> 骚操作</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#利用分支重置提交代码"><span class="toc-number">2.1.</span> <span class="toc-text"> 利用分支重置提交代码</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#将另一个远端仓库推送到自己的远端仓库"><span class="toc-number">2.2.</span> <span class="toc-text"> 将另一个远端仓库推送到自己的远端仓库</span></a></li></ol></li></ol>
    </nav>
  </div>
</aside>

<main class="main" role="main">
  <div class="content">
  <article id="post-Git基础使用方法" class="article article-type-post" itemscope itemtype="http://schema.org/BlogPosting">
    
    <div class="article-header">
      
        
  
    <h1 class="article-title" itemprop="name">
      Git基础使用方法
    </h1>
  

      
      <div class="article-meta">
        <span class="article-date">
    <i class="icon icon-calendar-check"></i>
	<a href="/blog/2019/02/20/Git基础使用方法/" class="article-date">
	  <time datetime="2019-02-20T04:32:46.000Z" itemprop="datePublished">2019-02-20</time>
	</a>
</span>
        
  <span class="article-category">
    <i class="icon icon-folder"></i>
    <a class="article-category-link" href="/blog/categories/教程/">教程</a>
  </span>

        
  <span class="article-tag">
    <i class="icon icon-tags"></i>
	<a class="article-tag-link" href="/blog/tags/git/">git</a>
  </span>


        
	<span class="article-read hidden-xs">
	    <i class="icon icon-eye-fill" aria-hidden="true"></i>
	    <span id="busuanzi_container_page_pv">
			<span id="busuanzi_value_page_pv">0</span>
		</span>
	</span>


        <span class="post-comment"><i class="icon icon-comment"></i> <a href="/blog/2019/02/20/Git基础使用方法/#comments" class="article-comment-link">评论</a></span>
        
	
		<span class="post-wordcount hidden-xs" itemprop="wordCount">字数统计: 712(字)</span>
	
	
		<span class="post-readcount hidden-xs" itemprop="timeRequired">阅读时长: 3(分)</span>
	

      </div>
    </div>
    <div class="article-entry marked-body" itemprop="articleBody">
      
        <p><strong>概述</strong></p>
<p>Git是一个免费的开源分布式版本控制系统，设计用于处理从小型到大型的所有项目，速度和效率都很高。</p>
<h2 id="git命令行"><a class="markdownIt-Anchor" href="#git命令行"></a> Git命令行</h2>
<p>参考:</p>
<ul>
<li>
<p><a href="https://www.cnblogs.com/nopnog/p/7763008.html" target="_blank" rel="noopener">Git基本应用</a></p>
</li>
<li>
<p><a href="https://www.git-scm.com/book/zh/v2/%E8%B5%B7%E6%AD%A5-%E5%91%BD%E4%BB%A4%E8%A1%8C" target="_blank" rel="noopener">官方Git使用文档</a></p>
</li>
</ul>
<h3 id="提交代码"><a class="markdownIt-Anchor" href="#提交代码"></a> 提交代码</h3>
<h4 id="1-配置用户"><a class="markdownIt-Anchor" href="#1-配置用户"></a> 1. 配置用户</h4>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git config --global user.email &quot;xxx@meitu.com&quot;</span><br><span class="line">git config --global user.name &quot;xxx&quot;</span><br></pre></td></tr></table></figure>
<h4 id="2-查看文件状态"><a class="markdownIt-Anchor" href="#2-查看文件状态"></a> 2. 查看文件状态</h4>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git status</span><br></pre></td></tr></table></figure>
<h4 id="3-添加到缓存"><a class="markdownIt-Anchor" href="#3-添加到缓存"></a> 3. 添加到缓存</h4>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git add test.cpp</span><br></pre></td></tr></table></figure>
<h4 id="4-提交到本地仓库"><a class="markdownIt-Anchor" href="#4-提交到本地仓库"></a> 4. 提交到本地仓库</h4>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git commit -m &quot;[feature] ....&quot;</span><br></pre></td></tr></table></figure>
<h4 id="5-推送到远端"><a class="markdownIt-Anchor" href="#5-推送到远端"></a> 5. 推送到远端</h4>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git push</span><br></pre></td></tr></table></figure>
<h3 id="拉取指定分支"><a class="markdownIt-Anchor" href="#拉取指定分支"></a> 拉取指定分支</h3>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git clone -b develop git@.....git</span><br></pre></td></tr></table></figure>
<h3 id="拉取子模块"><a class="markdownIt-Anchor" href="#拉取子模块"></a> 拉取子模块</h3>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git submodule sync --recursive</span><br><span class="line">git submodule update --init --recursive</span><br></pre></td></tr></table></figure>
<h3 id="切换分支"><a class="markdownIt-Anchor" href="#切换分支"></a> 切换分支</h3>
<h4 id="1-查看当前分支"><a class="markdownIt-Anchor" href="#1-查看当前分支"></a> 1. 查看当前分支</h4>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git branch</span><br></pre></td></tr></table></figure>
<h4 id="2-创建分支"><a class="markdownIt-Anchor" href="#2-创建分支"></a> 2. 创建分支</h4>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">git checkout -b develop</span><br><span class="line">或</span><br><span class="line">git branch develop</span><br><span class="line">或</span><br><span class="line">git checkout develop</span><br></pre></td></tr></table></figure>
<h4 id="3-切换分支"><a class="markdownIt-Anchor" href="#3-切换分支"></a> 3. 切换分支</h4>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git checkout master // 切换至本地master分支</span><br><span class="line">git checkout -b release/0.0.6 origin/release/0.0.6    // 拉取远端的分支并切换</span><br></pre></td></tr></table></figure>
<h4 id="4-合并分支"><a class="markdownIt-Anchor" href="#4-合并分支"></a> 4. 合并分支</h4>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git merge develop</span><br></pre></td></tr></table></figure>
<h4 id="5-删除分支"><a class="markdownIt-Anchor" href="#5-删除分支"></a> 5. 删除分支</h4>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git branch -d develop</span><br></pre></td></tr></table></figure>
<h3 id="丢弃某个文件的更改"><a class="markdownIt-Anchor" href="#丢弃某个文件的更改"></a> 丢弃某个文件的更改</h3>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git checkout -- readme.md</span><br></pre></td></tr></table></figure>
<blockquote>
<ul>
<li>若 <a href="http://readme.md" target="_blank" rel="noopener">readme.md</a> 修改后未放到暂存区, 则撤销至和版本库一模一样的状态</li>
<li>若 <a href="http://readme.md" target="_blank" rel="noopener">readme.md</a> 已添加至暂存区, 又作了修改, 则撤销至之前添加到暂存区的状态.</li>
</ul>
</blockquote>
<h3 id="将本地非空工程与远端创建的新仓库关联"><a class="markdownIt-Anchor" href="#将本地非空工程与远端创建的新仓库关联"></a> 将本地非空工程与远端创建的新仓库关联</h3>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git remote add origin git@github.com:账号/learngit.git</span><br></pre></td></tr></table></figure>
<p>之后可以将本地工程文件提交至远端</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git push -u origin master</span><br></pre></td></tr></table></figure>
<h3 id="查看提交记录"><a class="markdownIt-Anchor" href="#查看提交记录"></a> 查看提交记录</h3>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git log</span><br><span class="line">git log --pretty=oneline // 输出格式比较简洁</span><br></pre></td></tr></table></figure>
<h2 id="骚操作"><a class="markdownIt-Anchor" href="#骚操作"></a> 骚操作</h2>
<h3 id="利用分支重置提交代码"><a class="markdownIt-Anchor" href="#利用分支重置提交代码"></a> 利用分支重置提交代码</h3>
<ul>
<li>用途: 去除无效提交信息至主干分支</li>
<li>具体操作流程:
<ol>
<li>开发时, 从主干分支中开出功能分支</li>
<li>开发完毕准备合并入主干分支时, 从最新的功能分支上新建一个新的分支</li>
<li>然后将该新分支重置到当初从主干分支分出来的节点, 一次性提交功能分支的所有修改</li>
<li>合并重置分支至主干分支</li>
<li>删除功能分支</li>
<li>删除重置分支</li>
</ol>
</li>
</ul>
<h3 id="将另一个远端仓库推送到自己的远端仓库"><a class="markdownIt-Anchor" href="#将另一个远端仓库推送到自己的远端仓库"></a> 将另一个远端仓库推送到自己的远端仓库</h3>
<ul>
<li>
<p>新增远程仓库</p>
<p><img src="http://ww1.sinaimg.cn/large/929ea2a1gy1g0rne34np7j20vk0h2jtf.jpg" alt></p>
<p>随便取个名称, 并填充其<strong>git</strong>路径：</p>
<p><img src="http://ww1.sinaimg.cn/large/929ea2a1gy1g0rneocjm6j20ya0i40v5.jpg" alt></p>
</li>
<li>
<p>拉取另一个远端的<strong>master</strong>到本地<strong>master</strong></p>
<p><img src="http://ww1.sinaimg.cn/large/929ea2a1gy1g0rnezdcd7j20ni0jy7dk.jpg" alt></p>
<p><img src="http://ww1.sinaimg.cn/large/929ea2a1gy1g0rnftbi3uj21co0yax0c.jpg" alt></p>
</li>
<li>
<p>解决 <strong>git pull</strong> 失败 , 提示：<code>fatal: refusing to merge unrelated histories</code></p>
<p><img src="http://ww1.sinaimg.cn/large/929ea2a1gy1g0rnge192dj20xa0icgnp.jpg" alt></p>
<p>这个问题是因为 两个 根本不相干的 git 库， 一个是本地库， 一个是远端库， 然后本地要去推送到远端， 远端觉得这个本地库跟自己不相干， 所以告知无法合并</p>
<p>解决办法：把两段不相干的 分支进行强行合并, 再<strong>push</strong>到远端即可。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git pull origin master --allow-unrelated-histories</span><br></pre></td></tr></table></figure>
<ul>
<li>步骤1</li>
</ul>
<p><img src="http://ww1.sinaimg.cn/large/929ea2a1gy1g0rnjartq4j21dk0vm4ac.jpg" alt></p>
<ul>
<li>步骤二</li>
</ul>
<p><img src="http://ww1.sinaimg.cn/large/929ea2a1gy1g0rnjnzoyfj21mc0xw7wh.jpg" alt></p>
</li>
</ul>

      
    </div>
    <div class="article-footer">
      <!-- <blockquote class="mt-2x">
  <ul class="post-copyright list-unstyled">
    
    <li class="post-copyright-link hidden-xs">
      <strong>本文链接：</strong>
      <a href="http://zhulao.gitee.io/blog/2019/02/20/Git基础使用方法/" title="Git基础使用方法" target="_blank" rel="external">http://zhulao.gitee.io/blog/2019/02/20/Git基础使用方法/</a>
    </li>
    
    <li class="post-copyright-license">
      <strong>版权声明： </strong> 本博客所有文章除特别声明外，均采用 <a href="http://creativecommons.org/licenses/by/4.0/deed.zh" target="_blank" rel="external">CC BY 4.0 CN协议</a> 许可协议。转载请注明出处！
    </li>
  </ul>
</blockquote>


<div class="panel panel-default panel-badger">
  <div class="panel-body">
    <figure class="media">
      <div class="media-left">
        <a href="https://github.com/wzx3" target="_blank" class="img-burn thumb-sm visible-lg">
          <img src="/blog/images/avatar.jpeg" class="img-rounded w-full" alt="">
        </a>
      </div>
      <div class="media-body">
        <h3 class="media-heading"><a href="https://github.com/wzx3" target="_blank"><span class="text-dark">王竹兴</span><small class="ml-1x"></small></a></h3>
        <div></div>
      </div>
    </figure>
  </div>
</div>
 -->

    </div>
  </article>
  
    
  <section id="comments">
  	
  </section>


  
</div>

  <nav class="bar bar-footer clearfix" data-stick-bottom>
  <div class="bar-inner">
  
  <ul class="pager pull-left">
    
    <li class="prev">
      <a href="/blog/2019/02/20/GDB调试基础使用方法/" title="GDB调试基础使用方法"><i class="icon icon-angle-left" aria-hidden="true"></i><span>&nbsp;&nbsp;上一篇</span></a>
    </li>
    
    
    <li class="next">
      <a href="/blog/2019/02/19/Hexo-Github免费搭建个人静态博客/" title="Hexo+Github免费搭建个人静态博客"><span>下一篇&nbsp;&nbsp;</span><i class="icon icon-angle-right" aria-hidden="true"></i></a>
    </li>
    
    
    <li class="toggle-toc">
      <a class="toggle-btn collapsed" data-toggle="collapse" href="#collapseToc" aria-expanded="false" title="文章目录" role="button">
        <span>[&nbsp;</span><span>文章目录</span>
        <i class="text-collapsed icon icon-anchor"></i>
        <i class="text-in icon icon-close"></i>
        <span>]</span>
      </a>
    </li>
    
  </ul>
  
  
  
  <div class="bar-right">
    
    <div class="share-component" data-sites="weibo,qq,wechat,facebook,twitter" data-mobile-sites="weibo,qq,qzone"></div>
    
  </div>
  </div>
</nav>
  


</main>

  <footer class="footer" itemscope itemtype="http://schema.org/WPFooter">
	
	
    <ul class="social-links">
    	
        <li><a href="https://github.com/wzx3" target="_blank" title="Github" data-toggle="tooltip" data-placement="top"><i class="icon icon-github"></i></a></li>
        
        <li><a href="/blog/atom.xml" target="_blank" title="Rss" data-toggle="tooltip" data-placement="top"><i class="icon icon-rss"></i></a></li>
        
    </ul>

    <div class="copyright">
    	
        <div class="publishby">
        	Theme by <a href="https://github.com/cofess" target="_blank"> cofess </a>base on <a href="https://github.com/cofess/hexo-theme-pure" target="_blank">pure</a>.
        </div>
    </div>
</footer>
  <script src="//cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
<script>
window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')
</script>
<script src="/blog/js/plugin.min.js"></script>
<script src="/blog/js/application.js"></script>

    <script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: '文章',
            PAGES: '页面',
            CATEGORIES: '分类',
            TAGS: '标签',
            UNTITLED: '(未命名)',
        },
        ROOT_URL: '/blog/',
        CONTENT_URL: '/blog/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>
<script src="/blog/js/insight.js"></script>





   
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>





   






</body>
</html>